<template>
	<view class="warp">
		<!-- 顶部筛选 start -->
		<view class="top_search">
			<uv-input placeholder="搜索试卷" prefixIcon="search" v-model="keyword" prefixIconStyle="font-size: 22px;color: #909399">
				<template v-slot:suffix>
					<uv-button type="default" @click="search" size="mini" :hairline="true" color="#F1F1F5" :customTextStyle="{color:'#323233',fontSize:'14px'}" text="搜索"></uv-button>
				</template>
			</uv-input>
		</view>
		<!-- 顶部筛选 end -->
		<!-- 列表 start -->
		<view class="test_list">
			<view class="test_item" v-for="(v,k) in rows" :key="k">
				<view class="test_item_row" @click="jumpUrl('/pages/test/details?id='+v.id)">
					<view class="item_row_l">
						<uv-icon name="order" color="#79b1fe" size="48rpx"></uv-icon>
						<view class="test_item_title line_1">
							{{v.title}}
						</view>
					</view>
					<view class="createtime">
						{{customDate("Y-m-d",v.createtime)}}
					</view>
				</view>
			</view>
			<uv-load-more :status="apiStatus" />
		</view>
		<!-- 列表 end -->
		<!-- 底部tabbar start -->
		<bastTabbar :tabbar_index="2"></bastTabbar>
		<!-- 底部tabbar end -->
	</view>
</template>

<script>
	import bastTabbar from '@/component/base-tabbar.vue'
	export default {
		components: {
			bastTabbar,
		},
		onReachBottom() {
			console.log('onReachBottom')
			console.log('this.page',this.page)
			this.get_rows()
		},
		onLoad() {
			this.get_rows()
		},
		data() {
			return {
				rows: [],
				keyword: '',
				//
				page: 1,
				pagesize: 20,
				apiMore: true,
				apiStatus: 'loadmore',
				apiPost: false,
			}
		},
		methods: {
			search() {
				this.page = 1
				this.apiMore = true
				this.apiStatus = 'loadmore'
				this.apiPost = false
				this.rows = []
				this.get_rows()
			},
			async get_rows() {
				if (this.apiPost || this.apiMore===false) {
					return false
				}
				const res = await this.$myRequest({
					url: "test/lst",
					type: "post",
					data: {keyword:this.keyword,page:this.page,pagesize:this.pagesize},
				});
				this.page += 1
				if (res.code) {
					this.apiMore = res.data.length < this.pagesize ? false : true
					this.apiStatus = res.data.length < this.pagesize ? "nomore" : "loadmore"
					this.rows = this.rows.length > 0 ? [...this.rows, ...res.data] : res.data
				}
			},
		}
	}
</script>

<style lang="scss">
	.warp{
		background-color: #FFF;
		min-height: 100vh;
		max-width: 1600rpx;
		margin: auto;
		// 筛选顶部
		.top_search {
			padding: 4rpx;
			::v-deep .uv-button{
				padding: 13px 8px;
			}
		}
		.test_list{
			padding: 20rpx;
			font-size: 30rpx;
			.test_item{
				padding: 20rpx 0;
				border-bottom: 1px dashed #909399;
				.test_item_row{
					display: flex;
					justify-content: space-between;
					align-items: center;
					.item_row_l{
						display: flex;
						align-items: center;
						.test_item_title{
							margin-left: 10rpx;
						}
					}
					.createtime{
						width: 340rpx;
						text-align: right;
						font-size: 28rpx;
						color: crimson;
					}
				}
			}
		}
	}
</style>